/*
连表查询数据-----------------------------------------------------------------------------------------------
*
*
*/

/**
 * 双表连接查询
 * @param {database} database -数据库对象
 * @param {string} table1 -表1
 * @param {string} table2 -表2
 * @param {string} table1_field -表1连接字段
 * @param {string} table2_field -表2连接字段
 * @returns {res} 查询结果
 */
const datadoubletablequery = (database,table1,table2,table1_field,table2_field) => {
    return new Promise((resolve, reject) => {
        const sql = `select * from ${table1} join ${table2} on ${table1}.${table1_field} = ${table2}.${table2_field}`;
        database.query(sql, (err, res) => {
            if (err) {
                console.log(err.message);
                reject(err);
            } else {
                // console.log(res);
                resolve(res);
            }
        });
    });
}


module.exports = {
    datadoubletablequery
}